<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="f"%>



<!-- 文章详情模态框 -->
<div class="modal" id="articleDetalis" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="detailTitle"> </h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      
      <!-- 文章内容 -->
      <div class="modal-body" id="detailContent">
       		
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary" onclick="check(1)">通过</button>
        <button type="button" class="btn btn-danger" onclick="check(2)">拒绝</button>
        <button type="button" class="btn btn-primary" onclick="setHot(1)">热门</button>
        <button type="button" class="btn btn-primary" onclick="setHot(0)">非热门</button>
      </div>
    </div>
  </div>
</div>



	<table class = "table">
		<tr>
			<td>编号</td>
			<td>缩略图</td>
			<td>标题</td>
			<td>发布时间</td>
			<td>状态</td>
			<td>栏目</td>
			<td>热门</td>
			<td>分类</td>
			<td>作者</td>
		</tr>
		<!-- ,id,title,content,picture,channel_id,category_,user_id,hits,hot,status,deleted,created,updated,commentCnt,articleType -->
		<c:forEach items="${articlePage.list }" var="article">
			<tr>
				<td>${article.id }</td>
				<td>
				<img alt="无法显示图片" src="${article.picture }" width="50" height="30">
				</td>
				<td>
				<a href = "javascript:showArticleDetails(${article.id })">${article.title }</a>
				
				</td>
				<td>
				<fmt:formatDate value="${article.created }" pattern="yyyy-MM-dd"/>
				</td>
				<td>
					<c:choose>
						<c:when test="${article.status==0 }">待审核</c:when>
						<c:when test="${article.status==1 }">通过</c:when>
						<c:when test="${article.status==2 }">拒绝</c:when>
						<c:otherwise>其他</c:otherwise>
					</c:choose>
				
				</td>
				<td>${article.hot==1?'热门':'非热门' }</td>
				<td>${article.channel.name }</td>
				<td>${article.category.name }</td>
				<td>${article.author.username }</td>
			</tr>
		</c:forEach>
	</table>
	
	<nav aria-label="Page navigation example">
	  <ul class="pagination justify-content-end">
		    <li class="page-item">
		      <a class="page-link" onclick = "page(1)" href="#" tabindex="-1" aria-disabled="flase">首页</a>
		    </li>
		    
		    <c:forEach begin="${articlePage.pageNum-2 > 1?articlePage.pageNum:1 }" 
		    	end="${articlePage.pageNum+2<articlePage.pages?articlePage.pageNum+2:articlePage.pages }" step="1" var="page">
		    	
			    <li class="page-item">
			   	 	<a class="page-link" href="#" onclick = "page(${page})">${page }</a>
			    </li> 
		    </c:forEach>
		    
		    <li class="page-item">
		      <a class="page-link" href="#" onclick = "page(${articlePage.pages})">尾页</a>
		    </li>
	  </ul>
	</nav>
	<script type="text/javascript">
	
		function page(pageNum){
			alert(pageNum);
			$("#workContent").load("/article/findArticle?pageNum="+pageNum);	
		}
		
		var global_id = 0;
		
		function showArticleDetails(articleId){
			
			global_id = articleId;
			$.get("/article/getArticle",{articleId:articleId},function(msg){
				if( msg.errorid == 0 ){
					$(".modal-title").html(msg.t.title);
					$(".modal-body").html(msg.t.content);
					$("#articleDetalis").modal("show");
				}
			})
				
		}
		
		
		function check(articleStatus){
			
			$.get("/article/checkArticle",{id:global_id,status:articleStatus}),function(msg){
				$("#articleDetalis").modal("hide");
				global_id = 0;
			}
			
		}
		function setHot(articleStatus){
			
			$.get("/article/setHot",{id:global_id,hot:articleStatus}),function(msg){
				$("#articleDetalis").modal("hide");
				global_id = 0;
			}
			
		}
		
		 $('#articleDetalis').on('hidden.bs.modal', function () {
			$("#workContent").load("/article/findArticle?pageNum="+${articlePage.pageNum});
		} );
		
		
		
	
	</script>	
	
	

